package com.goods.controller.busniess;

import com.github.pagehelper.PageInfo;
import com.goods.business.service.SupplierService;
import com.goods.common.annotation.ControllerEndpoint;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.sun.org.apache.bcel.internal.generic.NEW;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description：
 * @version:
 * @author：ruixinag
 * @create：Created in 2021/11/8 20:07
 */
@Api(tags = "业务模块-供应商")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    //物资来源分页列表展示
    @ApiOperation("物资来源分页列表展示")
    @GetMapping("/findSupplierList")
    //@ControllerEndpoint
    public ResponseBean<Map> findSupplierList(
            @RequestParam Map map
    ) {
        PageInfo<SupplierVO> pageInfo = supplierService.findSupplierList(map);
        HashMap<Object, Object> result = new HashMap<>();

        result.put("rows", pageInfo.getList());
        result.put("total", pageInfo.getTotal());

        return ResponseBean.success(result);
    }

    //添加物资来源
    @ApiOperation("添加物资来源")
    @PostMapping("/add")
    public ResponseBean add(
            @RequestBody Supplier supplier
    ) {
        supplierService.add(supplier);
        return ResponseBean.success();
    }

    //添加物资来源
    @ApiOperation("添加物资来源")
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO> edit(
            @PathVariable Long id
    ) {
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    //更新数据
    @ApiOperation("更新数据")
    @PutMapping("/update/{id}")
    public ResponseBean update(
            @RequestBody Supplier supplier
    ) {
        supplierService.update(supplier);
        return ResponseBean.success();
    }

    //删除数据
    @ApiOperation("删除数据")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(
            @PathVariable Long id
    ) {
        supplierService.delete(id);
        return ResponseBean.success();
    }

    //获取全部信息,findAll
    @ApiOperation("删除数据")
    @GetMapping("/findAll")
    public ResponseBean<List<SupplierVO>> findAll(
    ) {
        List<SupplierVO> list = supplierService.findAll();
        return ResponseBean.success(list);
    }

}
